package com.jb.repair.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jb.repair.R;
import com.jb.repair.model.DocH1Model;
import com.jb.repair.model.DocH2Model;
import com.jb.repair.view.ListViewInScroll;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by gaobin on 2015/11/17.
 */
public class DocMenuH1Adapter extends BaseAdapter implements AdapterView.OnItemClickListener {
    private Context context;
    private List<DocH1Model> mData;
    private LayoutInflater mInflater;
    private ListViewInScroll lv;
    private OnItemChildListener  listener;

    public DocMenuH1Adapter(Context context, List<DocH1Model> mData,OnItemChildListener  listener) {
        this.context = context;
        this.mData = mData;
        mInflater = LayoutInflater.from(context);
        this.listener=listener;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = mInflater.inflate(R.layout.item_doc_menu_parent, null);
        TextView tv = (TextView) convertView.findViewById(R.id.tv_name);
         lv = (ListViewInScroll) convertView.findViewById(R.id.lv_data);
        final ImageView iv = (ImageView) convertView.findViewById(R.id.iv_show);

        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (lv.getVisibility() == View.VISIBLE) {
                    lv.setVisibility(View.GONE);
                    iv.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_show));
                } else {
                    lv.setVisibility(View.VISIBLE);
                    iv.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_unshow));
                }
            }
        });

        tv.setText(mData.get(position).type);
        DocMenuh2Adapter adapter = new DocMenuh2Adapter(context, mData.get(position).list);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(this);

        return convertView;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        listener.onItemClick(parent,view,position,id);
    }


    public interface OnItemChildListener {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id);
    }

    ;
}
